package leecode.q77;

import java.util.*;

public class Solution {
    int AA = 0;
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> list = new ArrayList<>();

    public List<List<Integer>> combine(int n, int k) {
        backTrack(1, n, k);
        return res;
    }

    public void backTrack(int start, int end, int count) {
        System.out.println("进入 start = " + start + ",end = " + end);
        if (list.size() == count) {
            res.add(new ArrayList<>(list));
            return;
        }
        for (int i = start; i <= end; i++) {
            list.add(i);
            ;
            backTrack(i + 1, end, count);
            list.remove(list.size() - 1);
        }
    }

    private void pp(int n) {
        for (int i = 0; i < n; i++) {
            System.out.print("|   ");
        }
    }

    /**
     * --------------------键盘字母----------------------------
     **/

    Map<String, String> map = new HashMap<>();
    List<String> result = new ArrayList<>();
    Stack<Character> stack = new Stack<>();

    public List<String> letterCombinations(String digits) {
        if (digits.equals("")) {
            return new ArrayList<>();
        }
        init();
        List<String> alphas = digitsToAlpha(digits);
        calc(alphas);
        return result;
    }

    private List<String> calc(List<String> als) {
        track(als);
        return null;
    }

    private void track(List<String> als) {
        if (als.size() == 0) {
            StringBuilder sb = new StringBuilder();
            for (Character character : stack) {
                sb.append(character);
            }
            result.add(sb.toString());
            return;
        }
        char[] chars = als.get(0).toCharArray();
        for (int i1 = 0; i1 < chars.length; i1++) {
            stack.push(chars[i1]);
            track(als.subList(1, als.size()));
            stack.pop();
        }
    }

    private void init() {
        map.put("2", "abc");
        map.put("3", "def");
        map.put("4", "ghi");
        map.put("5", "jkl");
        map.put("6", "mno");
        map.put("7", "pqrs");
        map.put("8", "tuv");
        map.put("9", "wxyz");
    }

    private List<String> digitsToAlpha(String digits) {
        char[] chars = digits.toCharArray();
        List<String> list = new ArrayList<>();
        for (char aChar : chars) {
            list.add(map.get(aChar + ""));
        }
        return list;
    }
}
